<template>
  <div>
    <nav-bar slot="left" class="back" @click="backClick">
      <div>
        <img src="~assets/img/common/back.svg" alt />
      </div>
      <div slot="conter" class="title">
        <div
          v-for="(item,i) in title"
          class="title-item"
          :key="i"
          :class="{actiov:i === currentIndex}"
          @click="titleClick(i)"
        >{{item}}</div>
      </div>
    </nav-bar>
  </div>
</template>

<script>
import NavBar from "components/common/navbar/NarBar";
export default {
  components: {
    NavBar,
  },
  data() {
    return {
      //标题通过遍历得到
      title: ["商品", "参数", "评论", "推荐"],
      //根据index判断是否那个高亮
      currentIndex: 0,
    };
  },
  methods: {
    //   高亮索引
    titleClick(i) {
      this.currentIndex = i;
      // 传递index出去 让其实现联动效果
      this.$emit('titleClick',i)
    },
    //路由后退
    backClick() {
      this.$router.back();
    },
  },
};
</script>

<style scoped>
.title {
  display: flex;
  font-size: 13px;
}

.title-item {
  flex: 1;
}

.active {
  color: var(--color-high-text);
}

.back img {
  margin-top: 12px;
}
</style>